<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['AddProcess'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
        :before-close="close"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ t('添加进程') }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar" style="height: calc(100% - 52px)">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @submit.prevent=""
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                >
                    <FormItem :label="t('提案') + '(' + t('中文')  + ')'" type="string" v-model="baTable.form.items!.name_cn" :input-attr="{ disabled: true }" />
                    <FormItem :label="t('提案') + '(' + t('韩文')  + ')'" type="string" v-model="baTable.form.items!.name_ko" :input-attr="{ disabled: true }" />
                    <FormItem :label="t('内容')" type="textarea" v-model="baTable.form.items!.describe" :input-attr="{rows: 6}" />
                    <FormItem :label="t('附加图片')" type="images" v-model="baTable.form.items!.images" :input-attr="{ hideSelectFile: true }" />
                    <FormItem :label="t('附加文件')" type="files" v-model="baTable.form.items!.files" :input-attr="{ hideSelectFile: true }" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="gb">{{ t('取消') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.table.filter.page = 1; baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('保存') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { FormInstance } from 'element-plus'

const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const close = (done: () => void) => {
    baTable.form.items = {}
    done();
}

const gb = () => {
    baTable.form.items = {}
    baTable.toggleForm()
}



</script>

<style scoped lang="scss">
:deep(.el-upload-list--picture-card .el-upload-list__item){
    width: 90px;
    height: 90px;
}
:deep(.el-upload--picture-card){
    width: 90px;
    height: 90px;
}
:deep(.ba-upload-select-image){
    width: 90px;
}
:deep(.ba-upload.files .el-button [class*=el-icon]+span){
    position: relative;
    top: -3px;
}
</style>
